import Vue from 'vue'
import Vuex from 'vuex'
import cart from './cart'
import user from './user'
import address from './address'
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)

/* const store = new Vuex.Store({
  modules: {
    cart,
    user
  },
  plugins: [
    createPersistedState()
  ]
}) */
const store = new Vuex.Store({
  modules: {
    cart,
    user,
    address
  },
  plugins: [
    createPersistedState({
      // storage: sessionStorage,
      reducer (val) { // val就是state
        return {
          user: val.user, // user 和 val.user 必须是同名
          cart: val.cart,
          address: val.address
        }
      }
    })
  ]
})

export default store
